package admin

import (
	"editor/constant"
	"editor/utils"
	"github.com/gin-gonic/gin"
	"net/http"
)

func LogoutHandler(c *gin.Context) {
	// 未登录判断
	if utils.GetSession(c, constant.UserName) != constant.Config.Login.User {
		c.HTML(http.StatusOK, "redirect.html", gin.H{
			"Title": constant.Config.App.Name,
			"Msg":   "未登录",
			"Time":  1,
			"Url":   "/login",
		})
		return
	}

	utils.SetSession(c, constant.UserName, "", -1)
	c.HTML(http.StatusOK, "redirect.html", gin.H{
		"Title": constant.Config.App.Name,
		"Msg":   "退出成功",
		"Time":  1,
		"Url":   "/",
	})
}
